package com.zxb.order.controller;

import com.zxb.common.exception.RRException;
import com.zxb.common.utlis.R;
import com.zxb.order.entity.OrderEntity;
import com.zxb.order.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@Slf4j
public class OrderController {

    @Autowired
    private OrderService orderService;

    @RequestMapping(value = "/findOrderByUserId/{userId}")
    public R findOrderByUserId(@PathVariable("userId") Integer userId){

        //模拟异常
        if(5 == userId){
            throw new RRException("非法参数异常");
        }

        //模拟超时
        if(6 == userId){
            try {
                Thread.sleep(5000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }

        log.info("根据userId:"+userId+"查询订单信息");
        List<OrderEntity> orderEntityList = orderService.listByUserId(userId);
        return R.ok().put("orders",orderEntityList);
    }

}
